package View.Add;

import Hander.Add.AddAchievementViewHander;
import View.LeaderView;
import entity.Achievement;

import javax.swing.*;
import java.awt.*;

public class AddAchievementView extends JDialog {
    private String tablesName;
    JPanel jPanel=new JPanel(new FlowLayout(FlowLayout.CENTER,10,20));

    //添加卡宴成
    JLabel AchievementID=new JLabel("AchievementID:",JLabel.RIGHT);
    JTextField AchievementIDTex=new JTextField();
    JLabel Category=new JLabel("Category:",JLabel.RIGHT);
    JTextField CategoryTex=new JTextField();
    JLabel AchievementLevel=new JLabel("AchievementLevel:",JLabel.RIGHT);
    JTextField AchievementLevelTex=new JTextField();
    JLabel Grade=new JLabel("Grade:",JLabel.RIGHT);
    JTextField GradeTex=new JTextField();//总分自动计算



    JButton addBtn=new JButton("修改");
    AddAchievementViewHander addAchievementViewHander;
    public AddAchievementView(LeaderView leaderView, String tableName){

        super(leaderView,"修改科研成果信息",true);

        setTablesName(tableName);
        addAchievementViewHander =new AddAchievementViewHander(this,leaderView );

        AchievementID.setPreferredSize(new Dimension(80,20));
        jPanel.add(AchievementID);
        AchievementIDTex.setPreferredSize(new Dimension(200,20));
        jPanel.add(AchievementIDTex);

        Category.setPreferredSize(new Dimension(80,20));
        jPanel.add(Category);
        CategoryTex.setPreferredSize(new Dimension(200,20));
        jPanel.add(CategoryTex);

        AchievementLevel.setPreferredSize(new Dimension(80,20));
        jPanel.add(AchievementLevel);
        AchievementLevelTex.setPreferredSize(new Dimension(200,20));
        jPanel.add(AchievementLevelTex);

        Grade.setPreferredSize(new Dimension(80,20));
        jPanel.add(Grade);
        GradeTex.setPreferredSize(new Dimension(200,20));
        jPanel.add(GradeTex);

        addBtn.addActionListener(addAchievementViewHander);
        jPanel.add(addBtn);
        Container contentPane=  getContentPane();
        contentPane.add(jPanel);

        setSize(350,300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);
    }
    public Achievement buildAchievement(){
        Achievement achievement=new Achievement();
        //只插入四条信息
        achievement.setAchievementID(Integer.valueOf(AchievementIDTex.getText()));
        achievement.setCategory(String.valueOf(CategoryTex.getText()));
        achievement.setAchievementLevel(String.valueOf(AchievementLevelTex.getText()));
        achievement.setGrade(Integer.valueOf(GradeTex.getText()));
        return achievement;
    }
    public String getTablesName() {
        return tablesName;
    }

    public void setTablesName(String tablesName) {
        this.tablesName = tablesName;
    }

}
